#include "StdAfx.h"
#include "CircuitBusDisObj.h"


CCircuitBusDisObj::CCircuitBusDisObj(CCircuitBus *pCircuitBus)
	: CCircuitUnitDisObj(pCircuitBus)
{
	m_dblColor[0] = pCircuitBus->GetColorR();
	m_dblColor[1] = pCircuitBus->GetColorG();
	m_dblColor[2] = pCircuitBus->GetColorB();
	m_dblLineWidth = pCircuitBus->GetLineWidth();
}

CCircuitBusDisObj::CCircuitBusDisObj(const CCircuitBusDisObj *pDisObj, CCircuitBus *pCircuitBus/* =NULL */)
	: CCircuitUnitDisObj(pDisObj, pCircuitBus)
{

}

CCircuitBusDisObj::~CCircuitBusDisObj(void)
{
}

void CCircuitBusDisObj::Serialize(CArchive & ar)
{
	CCircuitUnitDisObj::Serialize(ar);
}

void CCircuitBusDisObj::Display(CHoopsMap *pHoopsMap)
{
	CCircuitBus *pCirBus = (CCircuitBus *)GetEntityObj();
	if (!pCirBus)
	{
		return;
	}

	HC_KEY key_obj = INVALID_KEY;
	char sCirBusSeg[64];
	sprintf(sCirBusSeg, "line_%d", pCirBus->GetId());
	key_obj = HC_Open_Segment(sCirBusSeg);
		HC_Flush_Contents(".", "everything");

		HC_Set_Line_Weight(GetLineWidth());

		char szColorPattern[64];
		sprintf(szColorPattern, "lines = (r=%.2f g=%.2f b=%.2f)",
			GetColorR(), GetColorG(), GetColorB());
		HC_Set_Color(szColorPattern);

		HPoint ptStart, ptEnd;
		list<double> lsPos = pCirBus->GetPosList();
		list<double>::iterator it_pos=lsPos.begin();
		double posX=*it_pos;
		it_pos++;
		double posY=*it_pos;
		ptStart.Set(posX, posY);
		for (int i=0; i<pCirBus->GetPtCounts()-1; i++)
		{
			it_pos++;
			posX = *it_pos;

			it_pos++;
			posY = *it_pos;
			ptEnd.Set(posX, posY);
			HC_Insert_Line(ptStart.x, ptStart.y, ptStart.z, ptEnd.x, ptEnd.y, ptEnd.z);

			ptStart = ptEnd;
		}
	HC_Close_Segment();

	pHoopsMap->Delete(this);
	pHoopsMap->Add(key_obj, this);
}

void CCircuitBusDisObj::Transform(const CMatrix transf)
{

}

CObj *CCircuitBusDisObj::Clone() const
{
	return new CCircuitBusDisObj(this);
}

bool CCircuitBusDisObj::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return false;
}

eCircuitUnitType CCircuitBusDisObj::GetCircuitUnitType() const
{
	return CIRCUIT_BUS_DISOBJ;
}
